﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ETADTools.Lib
{
  public interface IFieldType
  {
    string ToParameterStyle();
    string ToDeclareStyle();
    string ToDataTypeID();
    string GetSize();
  }

  public class BitType : IFieldType
  {    
    public string ToParameterStyle()
    {
      return "@vbln";
    }

    public string ToDeclareStyle()
    {
      return "@bln";
    }

    public string ToDataTypeID()
    {
      return "-1";
    }

    public override string ToString()
    {
      return "BIT";
    }

    public string GetSize()
    {
      return string.Empty;
    }
  }

  public class IntType : IFieldType
  {
    public string ToParameterStyle()
    {
      return "@vint";
    }

    public string ToDeclareStyle()
    {
      return "@int";
    }

    public string ToDataTypeID()
    {
      return "-2";
    }

    public override string ToString()
    {
      return "INT";
    }

    public string GetSize()
    {
      return string.Empty;
    }
  }

  public class DecimalType : IFieldType
  {
    public int Precision { get; set; }
    public int Scale { get; set; }

    public DecimalType(int precision, int scale)
    {
      Precision = precision;
      Scale = scale;
    }

    public string ToParameterStyle()
    {
      return "@vdec";
    }

    public string ToDeclareStyle()
    {
      return "@dec";
    }

    public string ToDataTypeID()
    {
      return "-3";
    }

    public override string ToString()
    {
      return "DECIMAL";
    }

    public string GetSize()
    {
      return string.Format("({0}, {1})", Precision, Scale);
    }
  }

  public class DatetimeType : IFieldType
  {
    public string ToParameterStyle()
    {
      return "@vdtm";
    }

    public string ToDeclareStyle()
    {
      return "@dtm";
    }

    public string ToDataTypeID()
    {
      return "-4";
    }

    public override string ToString()
    {
      return "DATETIME";
    }

    public string GetSize()
    {
      return string.Empty;
    }
  }

  public class NVarcharType : IFieldType
  {
    public int Size { get; set; }

    public NVarcharType(int size)
    {
      Size = size;
    }

    public string ToParameterStyle()
    {
      return "@vstr";
    }

    public string ToDeclareStyle()
    {
      return "@str";
    }

    public string ToDataTypeID()
    {
      return "-5";
    }

    public override string ToString()
    {
      return "NVARCHAR";
    }

    public string GetSize()
    {
      if (Size == -1)
      {
        return "(max)";
      }
      else
      {
        return string.Format("({0})", Size);
      }
    }
  }

  public class NTextType : IFieldType
  {
    public string ToParameterStyle()
    {
      return "@vtxt";
    }

    public string ToDeclareStyle()
    {
      return "@txt";
    }

    public string ToDataTypeID()
    {
      return "-5";
    }

    public override string ToString()
    {
      return "NTEXT";
    }

    public string GetSize()
    {
      return string.Empty;
    }
  }
}
